package org.lhg.activiti.util;

public class CommonResult<T> {

    private int code;
    private String message;
    private T data;

    private CommonResult(T data) {
        this.code = 0;
        this.message = "success";
        this.data = data;
    }

    private CommonResult(CodeMessage codeMessage) {
        if (codeMessage == null) {
            return;
        }
        this.code = codeMessage.getCode();
        this.message = codeMessage.getMessage();
    }

    public static <T> CommonResult<T> success(T data) {
        return new CommonResult<T>(data);
    }

    public static <T> CommonResult<T> error(CodeMessage codeMessage) {
        return new CommonResult<T>(codeMessage);
    }

    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }


    public T getData() {
        return data;
    }

}
